//获取应用实例
import {
    request_post
} from '../../utils/request';
const app = getApp()
/* 组件 custom-component.js */
Page({
    data: {
        username: '',
        password: '',
        redirect: null
    },
    onLoad: function (options) {
        this.data.redirect = decodeURIComponent((options || {}).redirect) || null
    },
    formSubmit(e) {
        if (!e.detail.value.username) return wx.showToast({
            title: '请填写用户名',
            icon: 'none',
            duration: 2000
        })
        if (!e.detail.value.password) return wx.showToast({
            title: '请填写密码',
            icon: 'none',
            duration: 2000
        })
        request_post('/mini-app/auth/login/password', {
            "username": e.detail.value.username.trim(),
            "password": e.detail.value.password.trim(),
            "openId": wx.getStorageSync('openId') || ''
        }).then(res => {
            wx.setStorageSync('studentId', res.id)
            app.globalData.student = res
            // if (this.data.redirect) {
            //     if (this.data.redirect === '/pages/errorQuestion/index') {
            //         wx.switchTab({
            //             url: this.data.redirect
            //         })
            //     } else {
            //         wx.redirectTo({
            //             url: this.data.redirect
            //         })
            //     }
            //     return
            // }
            wx.navigateBack({
                delta: 1
            })
            return
        })
    }
})